package com.tju.welding.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiResponse {

    private int code;
    private String message;
    private Object result;

    public ApiResponse(Object data) {
        this.result = data;
    }

    public ApiResponse(Code info) {
        this.code = info.getCode();
        this.message = info.getMsg();
    }

    public static ApiResponse success(Object data) {
        return new ApiResponse(Code.OK.getCode(), Code.OK.getMsg(), data);
    }

    public static ApiResponse error(Code info) {
        return new ApiResponse(info);
    }

    public static ApiResponse error(Code info, Object data) {
        return new ApiResponse(info.getCode(), info.getMsg(), data);
    }

}